package com.chuang.server.util;

import com.chuang.server.pojo.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;


@Component
public class Token2User {
    /**
     * 返回 当前登录用户存在jwt里面的信息
     * @return
     */
    public User user(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        User user = (User)authentication.getPrincipal();
        return user;
    }


}
